const baseApi = 'https://gatewaytest.sztaizhou.com'
const isH5 = process.env.TARO_ENV === 'h5'

module.exports = {
  env: {
    NODE_ENV: '"production"',
  },
  defineConstants: {
    ENV_BASE_API: isH5 ? '"/api"' : JSON.stringify(baseApi),
  },
  mini: {
    commonChunks: ['runtime', 'vendors', 'taro', 'common', 'nutui'],
    webpackChain(chain) {
      chain.merge({
        optimization: {
          splitChunks: {
            cacheGroups: {
              nutui: {
                name: 'nutui',
                test: /[\\/]node_modules[\\/]@nutui[\\/]/,
                priority: 3,
                reuseExistingChunk: true,
              },
            },
          },
        },
      })
      /* chain
          .plugin("analyzer")
          .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin, []); */
    },
  },
  h5: {
    //如果h5端编译后体积过大，可以使用webpack-bundle-analyzer插件对打包体积进行分析。
    // 参考代码如下：
    webpackChain(chain) {
      /*     chain.merge({
        optimization: {
          splitChunks: {
            cacheGroups: {
              nutui: {
                name: "nutui",
                test: /[\\/]node_modules[\\/]@nutui[\\/]/,
                priority: 3,
                reuseExistingChunk: true,
              },
            },
          },
        },
      }),
        chain
          .plugin("analyzer")
          .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin, []); */
    },
  },
}
